define(["constant", "handlebars", "site", "public"], function (Constant, Handlebars, site) {

    var url = {
        selectVisitType: "manager/selectVisitType.do",
        submitVisit: "manager/submitVisit.do",
    }

    var submitVisitData = {};//提交回访

    var common = {
        init: function (type,order_id) {
            /*提交回访功能*/
            $("#commitVisit").unbind().on('click',function(){
                var remark = $("#visitWinboxtexTarea").val();
                var vist_time = $("#visit_time").val();
                if(!vist_time){
                    Constant.fn.Message("I","请输入回访时间");
                    return;
                }
                if(!remark){
                    Constant.fn.Message("I","请输入回访内容");
                    return;
                }
                site.send({
                    url: url.submitVisit,
                    data:{
                        url:$('[attachid=提交回访] li').attr('href'),
                        remarks: remark,
                        order_id: order_id,
                        visit_type: $("#visit_list").val(),
                        visit_time: vist_time,
                        type: type
                    },
                    callback: function (data) {
                        data = JSON.parse(data);
                        if (data.type == '1') {
                            Constant.fn.Message("T",data.msg);
                            $(".visitWinbox").hide();
                            /*var sortList = data.content;
                            var sortSource = $("#paymentSort_list_tpl").html();
                            var sortTemplate = Handlebars.compile(sortSource);
                            var sorthtml = sortTemplate(sortList);
                            var ps_id = data.content[0].id;*/
                        }else{
                            Constant.fn.Message("F",data.msg);
                        }
                    }
                })
            })
        },
        visit: function (order_id) {
            site.send({
                url: url.selectVisitType,
                callback: function (data) {
                    var list = JSON.parse(data);
                    if (list.type == '1') {
                        var list = JSON.parse(data);
                        var template = Handlebars.compile($("#visit_list_tpl").html());
                        var html = template(list.content);
                        $("#visit_list").html(html);
                        //$(".payMentWinbox").show();
                    } else {
                        Constant.fn.Message('F', list.msg);
                    }
                }
            })
            submitVisitData.order_id = order_id;
            $('[attachid=提交回访]').html('');
            $("#visitWinboxtexTarea").val("");
            $("#visit_time").val("");
            $(".visitWinbox").show()
            $(".visitSelect").val('-1');
        }
    }

    return common;

})